home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Revolution - Das Atari CD Magazin 1997
/
Revolution - Das Atari CD Magazin 1.iso
/
software
/
anwendng
/
qed_397
/
sourcen
/
windial.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-02
|
15KB
|
605 lines
#if 0
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <mydial.h>
#include "global.h"
#include "dial.h"
#include "obj.h"
#include "windows.h"
#include "windial.h"
/* exportierte Variablen *****************************************************/
/*****************************************************************************/
#define BACKDROP 0x2000 /* MagiC2 */
/* Damit das Dialogfenster ein BACKDROP gemeldet bekommt und ggf. den Cursor
* abschalten kann!!
*/
#define KIND (NAME|MOVER|BACKDROP)
#define FLAGS (WI_REDRAW)
LOCAL WORD find_obj (OBJECT *tree, WORD start_obj, WORD which);
LOCAL WORD fm_inifld (OBJECT *tree, WORD start_fld);
LOCAL VOID wi_draw (WINDOWP w, CONST RECT *r);
LOCAL VOID wi_click (WINDOWP w, MKINFO *mk);
LOCAL VOID wi_unclick (WINDOWP w);
LOCAL BOOLEAN wi_key (WINDOWP w, MKINFO *mk);
LOCAL VOID wi_top (WINDOWP window);
LOCAL VOID wi_ontop (WINDOWP window);
LOCAL VOID wi_untop (WINDOWP window);
LOCAL VOID wi_bottom (WINDOWP window);
LOCAL VOID wi_close (WINDOWP window);
/* Dialogverwaltung **********************************************************/
#define EDINIT 1
#define EDCHAR 2
#define EDEND 3
LOCAL WORD find_obj (OBJECT *tree, WORD start_obj, WORD which)
{
WORD obj, flag, theflag, inc;
obj = 0;
flag = EDITABLE;
inc = 1;
switch (which)
{
case FMD_BACKWARD:
inc = -1; /* fall thru */
case FMD_FORWARD:
obj = start_obj + inc;
break;
case FMD_DEFLT:
flag = DEFAULT;
break;
}
while (obj >= 0)
{
theflag = tree[obj].ob_flags;
if (theflag & flag)
return (obj);
if (theflag & LASTOB)
obj = -1;
else
obj += inc;
}
return (start_obj);
}
LOCAL WORD fm_inifld (OBJECT *tree, WORD start_fld)
{
if (!start_fld) /* position cursor on the starting field */
start_fld = find_obj(tree, 0, FMD_FORWARD);
return (start_fld);
}
/*****************************************************************************/
LOCAL VOID wi_click(WINDOWP w, MKINFO *mk)
{
DIALP d_ptr;
WORD cont, wbox;
RECT work;
TEDINFO *ted;
d_ptr = get_dial(w->link);
cont = TRUE;
/* position cursor on the selected editing field */
if ((d_ptr->next_obj != 0) && (d_ptr->edit_obj != d_ptr->next_obj))
{
d_ptr->edit_obj = d_ptr->next_obj;
d_ptr->next_obj = 0;
obj_edit(d_ptr->tree, d_ptr->edit_obj, 0, 0, &d_ptr->edit_idx, EDINIT, FALSE, &d_ptr->edit_obj, w->handle);
}
d_ptr->next_obj = objc_find (d_ptr->tree, ROOT, MAX_DEPTH, mk->mox, mk->moy);
if (d_ptr->next_obj == NIL)
{
mybeep();
d_ptr->next_obj = 0;
}
else
{
if (d_ptr->edit_obj && (d_ptr->tree[d_ptr->edit_obj].ob_type & 0xff) == G_USERDEF)
{
dial_drawcursor (d_ptr->tree, d_ptr->edit_obj, d_ptr->edit_idx, w->handle);
cont = form_Button (w->handle, d_ptr->tree, d_ptr->next_obj, mk->breturn, &d_ptr->next_obj, (SL_CB)NULL);
dial_drawcursor (d_ptr->tree, d_ptr->edit_obj, d_ptr->edit_idx, w->handle);
}
else
cont = form_Button (w->handle, d_ptr->tree, d_ptr->next_obj, mk->breturn, &d_ptr->next_obj, (SL_CB)NULL);
if ((d_ptr->tree[d_ptr->edit_obj].ob_flags & EXIT) && d_ptr->edit_obj != d_ptr->next_obj && cont)
{
d_ptr->next_obj = d_ptr->edit_obj;
cont = d_ptr->edit_obj = FALSE;
}
if (cont && (d_ptr->tree[d_ptr->next_obj].ob_flags & EDITABLE))
{
if (d_ptr->next_obj != d_ptr->edit_obj)
{
obj_edit (d_ptr->tree, d_ptr->edit_obj, mk->kstate, 0, &d_ptr->edit_idx, EDEND, FALSE, &d_ptr->edit_obj, w->handle);
d_ptr->edit_obj = d_ptr->next_obj;
d_ptr->next_obj = 0;
}
objc_rect(d_ptr->tree, d_ptr->edit_obj, &work, FALSE);
ted = (TEDINFO *)get_obspec (d_ptr->tree, d_ptr->edit_obj);
if (ted->te_font == SMALL)
wbox = 6;
else
wbox = sys_wchar;
if (ted->te_just != TE_LEFT)
{
work.w = work.w - dial_curspos (d_ptr->tree, d_ptr->edit_obj, min (ted->te_tmplen - 1, d_ptr->tree[d_ptr->edit_obj].ob_width / wbox), wbox);
if (ted->te_just == TE_CNTR)
work.w /= 2;
work.x += work.w;
}
d_ptr->edit_idx = dial_charpos (d_ptr->tree, d_ptr->edit_obj, mk->mox - work.x, wbox);
d_ptr->edit_obj = dial_setcpos (d_ptr->tree, d_ptr->edit_obj, &d_ptr->edit_idx);
}
}
if ((!cont) || ((d_ptr->next_obj != 0) && (d_ptr->next_obj != d_ptr->edit_obj)))
obj_edit(d_ptr->tree, d_ptr->edit_obj, mk->kstate, 0, &d_ptr->edit_idx, EDEND, FALSE, &d_ptr->edit_obj, w->handle);
if (!cont)
{
d_ptr->exit_obj = d_ptr->next_obj;
d_ptr->proc(d_ptr);
}
}
LOCAL VOID wi_unclick(WINDOWP w)
{
}
LOCAL BOOLEAN wi_key(WINDOWP w, MKINFO *mk)
{
UWORD knorm, kr;
DIALP d_ptr;
WORD cont;
d_ptr = get_dial(w->link);
knorm = mk->kreturn;
kr = nkc_n2gem(mk->kreturn);
cont = TRUE;
if ((d_ptr->tree[d_ptr->edit_obj].ob_flags & FLAGS15) && (knorm == (NKF_FUNC|NK_UP)
&& find_prev (d_ptr->tree, d_ptr->edit_obj) != NIL) || (knorm == (NKF_FUNC|NK_DOWN)
&& find_next (d_ptr->tree, d_ptr->edit_obj) != NIL))
{
obj_edit (d_ptr->tree, d_ptr->edit_obj, mk->kstate, kr, &d_ptr->edit_idx, EDCHAR, FALSE, &d_ptr->edit_obj, w->handle);
d_ptr->next_obj = d_ptr->edit_obj;
kr = 0;
}
else
cont = form_Keybd (w->handle, d_ptr->tree, d_ptr->edit_obj, mk->kstate, &d_ptr->next_obj, &kr);
if (kr)
{
obj_edit (d_ptr->tree, d_ptr->edit_obj, mk->kstate, kr, &d_ptr->edit_idx, EDCHAR, FALSE, &d_ptr->edit_obj, w->handle);
d_ptr->next_obj = d_ptr->edit_obj;
}
else
{
if ((d_ptr->tree[d_ptr->edit_obj].ob_flags & EXIT) && d_ptr->edit_obj != d_ptr->next_obj && cont)
{
d_ptr->next_obj = d_ptr->edit_obj;
cont = d_ptr->edit_obj = FALSE;
}
}
if ((!cont) || ((d_ptr->next_obj != 0) && (d_ptr->next_obj != d_ptr->edit_obj)))
obj_edit(d_ptr->tree, d_ptr->edit_obj, mk->kstate, 0, &d_ptr->edit_idx, EDEND, FALSE, &d_ptr->edit_obj, w->handle);
if (!cont)
{
d_ptr->exit_obj = d_ptr->next_obj;
(VOID) d_ptr->proc(spec);
}
else
{
/* position cursor on the selected editing field */
if ((d_ptr->next_obj != 0) && (d_ptr->edit_obj != d_ptr->next_obj))
{
d_ptr->edit_obj = d_ptr->next_obj;
d_ptr->next_obj = 0;
obj_edit(d_ptr->tree, d_ptr->edit_obj, 0, 0, &d_ptr->edit_idx, EDINIT, FALSE, &d_ptr->edit_obj, w->handle);
}
}
return TRUE;
}
LOCAL VOID wi_draw(WINDOWP w, CONST RECT *r)
{
DIALP d_ptr;
RECT r1;
d_ptr = get_dial(w->link);
r1 = w->work;
if (myrc_intersect(r, &r1))
objc_draw (d_ptr->tree, ROOT, MAX_DEPTH, r1.x, r1.y, r1.w, r1.h);
}
LOCAL VOID wi_top(WINDOWP w)
{
DIALP d_ptr;
d_ptr = get_dial(w->link);
obj_edit(d_ptr->tree, d_ptr->edit_obj, 0, 0, &d_ptr->edit_idx, EDINIT, FALSE,
&d_ptr->edit_obj, w->handle);
}
LOCAL VOID wi_ontop(WINDP w)
{
DIALP spec;
d_ptr = get_dial(w->link);
obj_edit(d_ptr->tree, d_ptr->edit_obj, 0, 0, &d_ptr->edit_idx, EDINIT, FALSE,
&d_ptr->edit_obj, w->handle);
}
LOCAL VOID wi_untop(WINDP w)
{
DIALP d_ptr;
d_ptr = get_dial(w->link);
obj_edit(d_ptr->tree, d_ptr->edit_obj, 0, 0, &d_ptr->edit_idx, EDEND, FALSE,
&d_ptr->edit_obj, w->handle);
}
LOCAL VOID wi_bottom(WINDOWP w)
{
DIALP d_ptr;
d_ptr = get_dial(w->link;
obj_edit(d_ptr->tree, d_ptr->edit_obj, 0, 0, &d_ptr->edit_idx, EDEND, FALSE,
&d_ptr->edit_obj, w->handle);
}
LOCAL VOID wi_close(WINDOWP w)
{
DIALP d_ptr;
d_ptr = get_dial(w->link);
{
/* Rahmen wieder anschalten */
if (planes == 1)
d_ptr->tree[0].ob_spec.obspec.framesize = d_ptr->save_frame;
else
dial_3Droot(TRUE, TRUE);
/* Position wieder korrigieren */
if (d_ptr->title_obj != -1)
{
d_ptr->tree[0].ob_y += d_ptr->wdelta;
undo_flags(d_ptr->tree, d_ptr->title_obj, HIDETREE);
}
destruct_dial(w->link);
destruct_window(w);
}
}
/***************************************************************************/
/* Kreieren eines Fensters */
/***************************************************************************/
LOCAL VOID crt_wdial(WORD icon, WINDP window)
{
window->flags = FLAGS;
window->draw = wi_draw;
window->click = wi_click;
window->unclick = wi_unclick;
window->key = wi_key;
window->top = wi_top;
window->ontop = wi_ontop;
window->untop = wi_untop;
window->bottom = wi_bottom;
window->close = wi_close;
window->mousenum = ARROW;
} /* crt_dial */
LOCAL BOOLEAN win_avail(VOID)
{
WORD h;
BOOLEAN ok;
h = wind_create(KIND, 0,0,0,0);
ok = (h > 0);
wind_delete(h);
return ok;
}
GLOBAL VOID openWDial(OBJECT *tree, WDIAL_CB proc, WORD start_obj)
{
DIALP d_ptr;
d_ptr = search_dial(tree);
if (d_ptr != NULL)
dial = (DIALP) malloc(sizeof(DIAL));
if (dial != NULL)
{
dial_center(tree);
dial->tree = tree;
dial->leave_dial = FALSE;
dial->start_obj = start_obj;
dial->proc = proc;
if (win_avail())
{
UBYTE winName[256];
if ((dial->win = create_window(KIND, CLASS_DIALOG, -1, crt_wdial))==NULL)
return;
dial->title_obj = find_xobj(tree, 19); /* Titel-Zeile suchen */
if (dial->title_obj >= 0)
objc_getstring(tree, dial->title_obj, (BYTE *)winName);
else
{
dial->title_obj = find_xobj(tree, 17); /* kein Titel, dann eben die Flugecke */
strcpy(winName, "**** Panne ****");
}
/* Rahmendicke merken und abschalten */
if (planes == 1)
{
dial->save_frame = dial->tree[0].ob_spec.obspec.framesize;
dial->tree[0].ob_spec.obspec.framesize = 0;
}
else
dial_3Droot(FALSE, FALSE);
dial->win->work.x = tree[0].ob_x;
dial->win->work.y = tree[0].ob_y;
/* Titel und Flugecke nicht mitzeichnen */
if (dial->title_obj != -1)
{
dial->wdelta = (tree[dial->title_obj].ob_y + tree[dial->title_obj].ob_height);
tree[0].ob_y -= dial->wdelta;
do_flags(tree, dial->title_obj, HIDETREE);
}
else
dial->wdelta = 0;
dial->win->work.w = tree[0].ob_width;
dial->win->work.h = tree[0].ob_height - dial->wdelta;
dial->draw_start = ROOT;
dial->draw_depth = MAX_DEPTH;
/* Damit man auch über die WINDOW-Struktur an die Dial-Daten kommt: */
dial->win->special = dial;
set_wname(dial->win, winName);
Arrow_mouse();
/* enable_menu(FALSE);*/
dial->next_obj = fm_inifld (dial->tree, dial->start_obj);
dial->edit_obj = 0;
open_window(dial->win);
/* position cursor on the selected editing field */
if ((dial->next_obj != 0) && (dial->edit_obj != dial->next_obj))
{
dial->edit_obj = dial->next_obj;
dial->next_obj = 0;
obj_edit(dial->tree, dial->edit_obj, 0, 0, &dial->edit_idx, EDINIT, FALSE, &dial->edit_obj, dial->win->handle);
}
}
else /* normaler Mydial */
{
/* nix zu tun? */
}
}
}
#if 0
LOCAL BOOLEAN default_exit(DIALP d)
{
if (d != NULL)
{
undo_state(d->tree, d->exit_obj, SELECTED);
deleteDial(d);
}
return TRUE;
}
GLOBAL DIALP newDial(OBJECT *tree, BOOLEAN (*exit_proc)(DIALP window), WORD def)
{
DIALP dial;
dial = (DIALP) malloc(sizeof(DIAL));
if (dial != NULL)
{
dial_center(tree);
dial->tree = tree;
dial->leave_dial = FALSE;
dial->start_obj = def;
dial->exit_proc = exit_proc;
if (use_wdial && win_avail())
{
UBYTE winName[256];
if ((dial->win = create_window(KIND, CLASS_DIALOG, -1, crt_wdial))==NULL)
return NULL;
dial->title_obj = find_xobj(tree, 19); /* Titel-Zeile suchen */
if (dial->title_obj >= 0)
objc_getstring(tree, dial->title_obj, (BYTE *)winName);
else
{
dial->title_obj = find_xobj(tree, 17); /* kein Titel, dann eben die Flugecke */
strcpy(winName, "**** Panne ****");
}
/* Rahmendicke merken und abschalten */
if (planes == 1)
{
dial->save_frame = dial->tree[0].ob_spec.obspec.framesize;
dial->tree[0].ob_spec.obspec.framesize = 0;
}
else
dial_3Droot(FALSE, FALSE);
dial->win->work.x = tree[0].ob_x;
dial->win->work.y = tree[0].ob_y;
/* Titel und Flugecke nicht mitzeichnen */
if (dial->title_obj != -1)
{
dial->wdelta = (tree[dial->title_obj].ob_y + tree[dial->title_obj].ob_height);
tree[0].ob_y -= dial->wdelta;
do_flags(tree, dial->title_obj, HIDETREE);
}
else
dial->wdelta = 0;
dial->win->work.w = tree[0].ob_width;
dial->win->work.h = tree[0].ob_height - dial->wdelta;
dial->draw_start = ROOT;
dial->draw_depth = MAX_DEPTH;
/* Damit man auch über die WINDOW-Struktur an die Dial-Daten kommt: */
dial->win->special = dial;
set_wname(dial->win, winName);
}
else /* normaler Mydial */
{
/* nix zu tun? */
}
} /* if != NULL */
return dial;
}
GLOBAL VOID openDial(DIALP d)
{
if (d != NULL)
{
if (use_wdial)
{
Arrow_mouse();
enable_menu(FALSE);
wdial_is_open++;
d->next_obj = fm_inifld (d->tree, d->start_obj);
d->edit_obj = 0;
open_window(d->win);
/* position cursor on the selected editing field */
if ((d->next_obj != 0) && (d->edit_obj != d->next_obj))
{
d->edit_obj = d->next_obj;
d->next_obj = 0;
obj_edit(d->tree, d->edit_obj, 0, 0, &d->edit_idx, EDINIT, FALSE, &d->edit_obj, d->win->handle);
}
}
else
{
BOOLEAN leave_dial = FALSE;
Arrow_mouse();
open_dial(d->tree, FALSE, NULL, &(d->dial));
dial_draw(&(d->dial));
while (!leave_dial)
{
d->exit_obj = dial_do(&(d->dial), &d->start_obj);
leave_dial = d->exit_proc(d);
}
}
}
}
GLOBAL VOID deleteDial(DIALP d)
{
if (d != NULL)
{
if (use_wdial)
{
/* Rahmen wieder anschalten */
if (planes == 1)
d->tree[0].ob_spec.obspec.framesize = d->save_frame;
else
dial_3Droot(TRUE, TRUE);
/* Position wieder korrigieren */
if (d->title_obj != -1)
{
d->tree[0].ob_y += d->wdelta;
undo_flags(d->tree, d->title_obj, HIDETREE);
}
destruct_window(d->win);
free(d);
enable_menu(TRUE);
wdial_is_open--;
if (wdial_is_open < 0)
form_alert(1,"[1][wdial_is_open < 0!!!][OK]");
}
else
{
dial_end(&(d->dial));
free(d);
Last_mouse();
}
d = NULL;
}
}
GLOBAL VOID simpleDial(OBJECT *tree)
{
DIALP dial;
dial = newDial(tree, default_exit, 0);
if (dial != NULL)
{
if (use_wdial)
openDial(dial);
else
HndlDial(tree, 0, TRUE, NULL, NULL);
}
}
GLOBAL VOID drawDial(DIALP d, WORD start_obj, WORD depth)
{
if (d != NULL)
{
if (use_wdial)
{
d->draw_start = start_obj;
d->draw_depth = depth;
redraw_window(d->win, &d->win->work);
d->draw_start = ROOT;
d->draw_depth = MAX_DEPTH;
}
else
{
objc_draw(d->tree, start_obj, depth, d->dial.x, d->dial.y, d->dial.w, d->dial.h);
}
}
}
GLOBAL VOID deselBtn(DIALP d, WORD btn)
{
if (d != NULL)
{
undo_state(d->tree, btn, SELECTED);
drawDial(d, btn, 1);
}
}
#endif
#endif